home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbinit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-03-07  |  8.7 KB  |  297 lines

  1. (*===========================================================================*)
  2. (* Procedure for initializing                                                *)
  3. (*                                                                           *)
  4. (*   Copyright 1988, 1989, 1990, 1991, 1992 by H. Roy Engehausen.  All       *)
  5. (*   rights reserved.                                                        *)
  6. (*                                                                           *)
  7. (*===========================================================================*)
  8.  
  9. {$UNDEF DEBUG}
  10.  
  11. UNIT BBINIT;
  12.  
  13. {$O+} {This procedure gets overlayed}
  14.  
  15. INTERFACE
  16.  
  17. PROCEDURE initialize;
  18. PROCEDURE tinit;
  19. PROCEDURE tclose;
  20.  
  21. IMPLEMENTATION
  22.  
  23. USES
  24.   CRT,
  25.   DOS,
  26.   bbaux,
  27.   bbdummy,
  28.   bbfwd,
  29.   bbmisc,
  30.   bbmisc4,
  31.   bbopr,
  32.   bbrunerr,
  33.   bbsdata,
  34.   bbsess,
  35.   bbsrt,
  36.   bbstr,
  37.   bbtask,
  38.   bbtime,
  39.   bbuf,
  40.   bbwin;
  41.  
  42. CONST debug = FALSE;
  43.  
  44. {$I BBTINIT.PAS}
  45.  
  46. PROCEDURE initialize;
  47.  
  48.   VAR
  49.     buff_size     : WORD;
  50.     i             : WORD;
  51.     min_time      : LONGINT;
  52.     work_tcb      : tcb_ptr;
  53.  
  54.   BEGIN;
  55.  
  56.   (*-------------------------------------------------------------------------*)
  57.   (* Initialize                                                              *)
  58.   (*-------------------------------------------------------------------------*)
  59.  
  60.   shutdown_switch := FALSE;
  61.   main_switch     := FALSE;
  62.  
  63.   fwd_command     := '';
  64.  
  65.   (*-------------------------------------------------------------------------*)
  66.   (* Initialize main tcb -- Put the call and stuff in the TCB                *)
  67.   (*-------------------------------------------------------------------------*)
  68.  
  69.   active_tcb^.window                := window_monitor;
  70.   active_tcb^.max_pac               := 128;
  71.   active_tcb^.tcb_name              := '';
  72.  
  73.   active_tcb^.tcb_type              := th_main;
  74.   active_tcb^.tcb_ignore_lc         := TRUE;
  75.   active_tcb^.tcb_ignore_port_chan  := TRUE;
  76.   active_tcb^.tcb_sysop_pw_ok       := TRUE;
  77.   active_tcb^.tcb_never_kill        := TRUE;
  78.  
  79.   active_tcb^.uid_data.user_i_ptr   := find_uid(opt_block.this_bb_sign);
  80.  
  81.   IF active_tcb^.uid_data.user_i_ptr <> NIL THEN
  82.     active_tcb^.uid_data := get_uid(active_tcb^.uid_data.user_i_ptr)^
  83.   ELSE
  84.     BEGIN;
  85.       uid_init(@active_tcb^.uid_data);
  86.       active_tcb^.uid_data.user_id := opt_block.this_bb_sign;
  87.     END;
  88.  
  89.   active_tcb^.uid_data.user_class := user_c_lsu;
  90.   active_tcb^.uid_data.user_last  := current_day_time;
  91.   active_tcb^.uid_data.user_port  := 'L';
  92.  
  93.   active_tcb^.last_l_time         := active_tcb^.uid_data.user_l_time;
  94.  
  95.   IF active_tcb^.uid_data.user_i_ptr = NIL THEN
  96.     add_uid(@active_tcb^.uid_data)
  97.   ELSE
  98.     update_uid(@active_tcb^.uid_data);
  99.  
  100.   (*-------------------------------------------------------------------------*)
  101.   (* Initialize the TNCs                                                     *)
  102.   (*-------------------------------------------------------------------------*)
  103.  
  104.   {$IFDEF DEBUG}
  105.     WRITELN('TNCinit');
  106.   {$ENDIF}
  107.  
  108.   tinit;
  109.  
  110.   (*-----------------------------------------------------------------------*)
  111.   (* Schedule forwards                                                     *)
  112.   (*-----------------------------------------------------------------------*)
  113.  
  114.   min_time := current_day_time + ticks_per_min + (ticks_per_min SHR 1);
  115.  
  116.   active_port := ring_port;
  117.  
  118.   REPEAT
  119.  
  120.     WITH active_port^ DO
  121.       BEGIN;
  122.  
  123.         IF port_no_out_fwd THEN
  124.           sked_fwd := max_time
  125.         ELSE
  126.           BEGIN;
  127.             sked_fwd  := time_next_hour(fwd_min);
  128.             IF sked_fwd < min_time THEN
  129.               sked_fwd := min_time;
  130.           END;
  131.  
  132.         active_port := next_port;
  133.  
  134.       END;
  135.  
  136.   UNTIL active_port = ring_port;
  137.  
  138.   (*-------------------------------------------------------------------------*)
  139.   (* Start operator's task                                                   *)
  140.   (*-------------------------------------------------------------------------*)
  141.  
  142.   {$IFDEF DEBUG}
  143.     WRITELN('OPRinit');
  144.   {$ENDIF}
  145.  
  146.   work_tcb := task_create(@operator_task_start, operator_stack_size);
  147.   IF work_tcb = NIL THEN
  148.     BEGIN;
  149.       WRITELN('***** FATAL ERROR *****');
  150.       WRITELN('Could not start operator task');
  151.       HALT;
  152.     END;
  153.  
  154.   WITH work_tcb^ DO
  155.     BEGIN;
  156.       tcb_type            := th_operator;
  157.       tcb_name            := '';
  158.       tcb_console         := TRUE;
  159.       tcb_port            := @dummy_port;
  160.       channel             := 0;
  161.       port_chan_s         := 'LO';
  162.       window              := window_operator;
  163.       w_color             := opt_block.operator_color;
  164.       tcb_never_kill      := TRUE;
  165.       tcb_sysop_pw_ok     := TRUE;
  166.  
  167.       IF opt_block.opt_suppress_pfx THEN
  168.         max_pac := special_max_pac_wop
  169.       ELSE
  170.         max_pac := special_max_pac_wp;
  171.  
  172.     END;
  173.  
  174.   work_tcb^.uid_data.user_i_ptr   := find_uid(opt_block.sysop_sign);
  175.  
  176.   IF work_tcb^.uid_data.user_i_ptr <> NIL THEN
  177.     work_tcb^.uid_data := get_uid(work_tcb^.uid_data.user_i_ptr)^
  178.   ELSE
  179.     BEGIN;
  180.       uid_init(@work_tcb^.uid_data);
  181.       work_tcb^.uid_data.user_id := opt_block.sysop_sign;
  182.     END;
  183.  
  184.   work_tcb^.uid_data.user_class := user_c_lsu;
  185.   work_tcb^.uid_data.user_last  := current_day_time;
  186.   work_tcb^.uid_data.user_port  := 'L';
  187.  
  188.   work_tcb^.last_l_time         := work_tcb^.uid_data.user_l_time;
  189.  
  190.   IF work_tcb^.uid_data.user_i_ptr = NIL THEN
  191.     add_uid(@work_tcb^.uid_data)
  192.   ELSE
  193.     update_uid(@work_tcb^.uid_data);
  194.  
  195.   (*-------------------------------------------------------------------------*)
  196.   (* Start forward TCB                                                       *)
  197.   (*-------------------------------------------------------------------------*)
  198.  
  199.   {$IFDEF DEBUG}
  200.     WRITELN('FWDinit');
  201.   {$ENDIF}
  202.  
  203.   work_tcb := task_create(@forward_task_start, forward_stack_size);
  204.   IF work_tcb = NIL THEN
  205.     BEGIN;
  206.       WRITELN('***** FATAL ERROR *****');
  207.       WRITELN('Could not start forward process task');
  208.       HALT;
  209.     END;
  210.  
  211.   WITH work_tcb^ DO
  212.     BEGIN;
  213.       tcb_type            := th_fwd_control;
  214.       uid_data            := ring_tcb^.uid_data;
  215.       uid_data.user_i_ptr := ring_tcb^.uid_data.user_i_ptr;
  216.       tcb_console         := TRUE;
  217.       tcb_port            := @dummy_port;
  218.       tcb_name            := '';
  219.       max_pac             := special_max_pac_wp;
  220.       window              := window_connect;
  221.       w_color             := opt_block.operator_color;
  222.       tcb_sysop_pw_ok     := TRUE;
  223.       tcb_never_kill      := TRUE;
  224.  
  225.     END;
  226.  
  227.   (*-------------------------------------------------------------------------*)
  228.   (* Start auxiliary processes -- One per port                               *)
  229.   (*-------------------------------------------------------------------------*)
  230.  
  231.   {$IFDEF DEBUG}
  232.     WRITELN('AUXinit');
  233.   {$ENDIF}
  234.  
  235.   active_port := ring_port;
  236.  
  237.   REPEAT
  238.  
  239.     active_tcb^.tcb_port := active_port;
  240.  
  241.     IF NOT active_port^.port_sub_port THEN
  242.       BEGIN;
  243.  
  244.         {$IFDEF DEBUG}
  245.           WRITELN('Activate aux -- ', active_port^.port_char);
  246.           DELAY(1000);
  247.         {$ENDIF}
  248.  
  249.         IF (active_port^. port_type = port_modem)
  250.                             OR (active_port^. port_type = port_null_modem) THEN
  251.           work_tcb := task_create(@aux_task_start, teleaux_stack_size)
  252.         ELSE
  253.           work_tcb := task_create(@aux_task_start, auxilary_stack_size);
  254.  
  255.         IF work_tcb = NIL THEN
  256.           BEGIN;
  257.             WRITELN('***** FATAL ERROR *****');
  258.             WRITELN('Could not start aux process');
  259.             HALT;
  260.           END;
  261.  
  262.         active_port^.aux_thread := work_tcb;
  263.  
  264.         WITH work_tcb^ DO
  265.           BEGIN;
  266.             tcb_type             := th_aux;
  267.             tcb_port             := active_port;
  268.             port_chan_s[1]       := active_port^.port_char;
  269.             port_chan_s[2]       := '0';
  270.             channel              := 0;
  271.             uid_data             := ring_tcb^.uid_data;
  272.             tcb_ignore_lc        := TRUE;
  273.             tcb_ignore_port_chan := TRUE;
  274.             tcb_name             := '';
  275.             max_pac              := special_max_pac_wp;
  276.             window               := window_monitor;
  277.             w_color              := active_port^.port_color;
  278.             tcb_sysop_pw_ok      := TRUE;
  279.             tcb_never_kill       := TRUE;
  280.           END;
  281.  
  282.       END;
  283.  
  284.     active_port := active_port^.next_port;
  285.  
  286.   UNTIL active_port = ring_port;
  287.  
  288.   (*-------------------------------------------------------------------------*)
  289.   (* Save count of overhead tasks                                            *)
  290.   (*-------------------------------------------------------------------------*)
  291.  
  292.   overhead_tcb_count := alive_tcb_count;
  293.  
  294. END;
  295.  
  296. END.
  297.